package com.wan.api.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wan.entity.GameForum;
import com.wan.service.GameForumService;
import entity.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 论坛表 前端控制器
 * </p>
 *
 * @author vicente
 * @since 2021-05-19
 */
@RestController
@RequestMapping("/bs/game")
public class GameForumController extends BaseController {
    @Autowired
    private GameForumService forumService;

    @PostMapping("/forum/save")
    public ResultBean forumSave(@RequestBody String string){
        JSONObject jsonObject = JSON.parseObject(string);
        GameForum forum = new GameForum();
        forum.setCreateTime(new Date());
        forum.setImgSrc(jsonObject.getString("imgSrc"));
        forum.setUpCount(0);
        forum.setText(jsonObject.getString("text"));
        forum.setUserId(getUserId());
        forumService.save(forum);
        return new ResultBean(200,"成功");
    }
}
